//
//  CellOfDidianTrip.m
//  project-A (pianke)
//
//  Created by dllo on 16/2/29.
//  Copyright © 2016年 scott. All rights reserved.
//

#import "CellOfDidianTrip.h"
#import "ModelOfDidianTrip.h"
#import <UIImageView+WebCache.h>

#define WIDTH self.contentView.bounds.size.width
#define HEIGHT self.contentView.bounds.size.height

@interface CellOfDidianTrip ()

@property (nonatomic, retain) UILabel *label_name;
@property (nonatomic, retain) UILabel *label_day;
@property (nonatomic, retain) UILabel *label_des;
@property (nonatomic, retain) UILabel *label_count;
@property (nonatomic, retain) UIImageView *imgDidian;
@property (nonatomic, retain) UIImageView *imgDate;
@property (nonatomic, retain) UIImageView *imgBackground;

@end


@implementation CellOfDidianTrip

-(void)dealloc{
    
    [_label_count release];
    [_label_day release];
    [_label_des release];
    [_label_name release];
    
    [_imgBackground release];
    [_imgDate release];
    [_imgDidian release];
    [super dealloc];
    
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createview];
        
    }
    return self;
}

-(void)createview{
    self.imgBackground = [[UIImageView alloc]init];
    [self.contentView addSubview:self.imgBackground];
    [self.imgBackground release];
    
    self.label_count = [[UILabel alloc]init];
    self.label_count.font = [UIFont fontWithName:@"Arial-BoldMT" size:12];
    self.label_count.textColor = [UIColor whiteColor];
    
    [self.contentView addSubview:self.label_count];
    [self.label_count release];
    
    self.label_day = [[UILabel alloc]init];
    self.label_day.font = [UIFont fontWithName:@"Arial-BoldMT" size:12];
    self.label_day.textColor = [UIColor whiteColor];
    [self.contentView addSubview:self.label_day];
    
    [self.label_day release];
    
    self.label_des = [[UILabel alloc]init];
    
    
    self.label_des.font = [UIFont fontWithName:@"Arial" size:15];
    self.label_des.numberOfLines = 0;
    
    [self.contentView addSubview:self.label_des];
    [self.label_des release];
    
    
    self.label_name = [[UILabel alloc]init];
    [self.contentView addSubview:self.label_name];
    
    self.label_name.textColor = [UIColor whiteColor];
    
    self.label_name.font = [UIFont fontWithName:@"Arial-BoldMT" size:22];
    [self.label_name release];
    
    self.imgDate = [[UIImageView alloc]init];
    [self.contentView addSubview:self.imgDate];
    [self.imgDate release];
    
    self.imgDidian = [[UIImageView alloc]init];
    [self.contentView addSubview:self.imgDidian];
    
    [self.imgDidian release];
    
}

-(void)passModel:(ModelOfDidianTrip *)model{
    
    self.label_name.text = model.name;
    self.label_des.text = model.description_title;
    self.label_day.text = [NSString stringWithFormat:@"%@天",model.plan_days_count];
    self.label_count.text = [NSString stringWithFormat:@"%@个旅行地",model.plan_nodes_count];
    
    [self.imgBackground sd_setImageWithURL:[NSURL URLWithString:model.image_url] placeholderImage:nil options:SDWebImageProgressiveDownload];
    
    self.imgDate.image = [UIImage imageNamed:@"time"];
    self.imgDidian.image = [UIImage imageNamed:@"didian"];
    
}

- (void)layoutSubviews {
    [super layoutSubviews];
    self.imgBackground.frame = CGRectMake(10, 5, WIDTH- 20, (HEIGHT - 10)/5 *3);
    self.label_des.frame = CGRectMake(10, (HEIGHT - 10)/5 *3 + 5, WIDTH - 20, (HEIGHT - 10)/5 *2);
    
    self.label_name.frame = CGRectMake(20, (5 + (HEIGHT - 10)/5 *3)-70 , WIDTH - 40, 40);
    self.imgDate.frame = CGRectMake(20, (5 + (HEIGHT - 10)/5 *3) - 30, 16, 16);
    self.label_day.frame = CGRectMake(20 + 16, (5 + (HEIGHT - 10)/5 *3) - 30, 25, 16);
    self.imgDidian.frame = CGRectMake(20 + 16 + 25, (5 + (HEIGHT - 10)/5 *3) - 30, 16, 16);
    self.label_count.frame = CGRectMake(20 + 16 + 25+ 16, (5 + (HEIGHT - 10)/5 *3) - 30, 100, 16);
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
